package cn.itcast.controller.system;

import cn.itcast.base.BaseController;
import cn.itcast.domain.user.User;
import cn.itcast.service.system.UserService;
//import org.springframework.amqp.core.AmqpTemplate;
import cn.itcast.utils.commons.MailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.mail.MessagingException;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/system/feedback")
public class FeedbackController extends BaseController {

    /*@Autowired
    private AmqpTemplate amqpTemplate;*/

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/to",name = "反馈信息页面")
    public String go() {
        return "system/feedback/feedback-go";
    }

    @RequestMapping(value = "/go",name = "反馈信息")
    public String inter(String remark) {
        Map<String, String> map = new HashMap<>();
        map.put("emailMsg", remark);
        System.out.println(remark);
        if (user.getDegree() > 1) {
            User user1 = userService.findUserDegree(companyName, 1);
            map.put("email", user1.getEmail());

            try {
                MailUtils.sendMail(map.get("email"), map.get("emailMsg"));
            } catch (MessagingException e) {
                e.printStackTrace();
            }
            //amqpTemplate.convertAndSend("email",map);
        } else if (user.getDegree() == 1) {
            String e = "SaaS公司";
            User saas = userService.findUserDegree(e, 0);
            map.put("email", saas.getEmail());

            try {
                MailUtils.sendMail(map.get("email"), map.get("emailMsg"));
            } catch (MessagingException e2) {
                e2.printStackTrace();
            }
            //amqpTemplate.convertAndSend("email",map);
        }
        return "system/feedback/feedback-go";
    }
}
